var $ = require("jquery");
require("jquery.cookie");

module.exports = {
	/**
	 * 格式化字符串
	 * ("{}{}",["a","b"])==>"ab"
	 * ("{0}{0}{1}",["a","b"])==>"aab"
	 * @param  {[type]} format [description]
	 * @param  {[type]} args   [description]
	 * @return {[type]}        [description]
	 */
	format: function(format, args) {
		for (var i = 0; i < args.length; i++) {
			format = format.replace(/\{\s*\}/, args[i]);
		}
		//{0}
		for (var i = 0; i < args.length; i++) {
			var reg = new RegExp('\\{' + i + '\\}', 'g');
			if (reg.test(format))
				format = format.replace(reg, args[i]);
		}
		return format;
	},
	checklogin:function(){
		var sessionid = $.cookie("sessionid")
		if (!sessionid || sessionid === "") {
			location.href = "login.html";
		}
	},

};